<?php

declare(strict_types=1);

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

/**
 *  女用户黑名单
 */
class HostBlacklist extends Model
{
    protected $table = 'host_blacklist';
    protected $fillable = ['user_id', 'flag'];

    public function userProfile()
    {
        return $this->belongsTo(UserProfile::class, 'user_id', 'user_id');
    }

    public function userInfo()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    static function getUids()
    {
        return self::where('flag', 1)->pluck('user_id')->toArray();
    }

    static function addHost($userId = 0)
    {
        return self::updateOrCreate(['user_id' => $userId], ['user_id' => $userId, 'flag' => 1]);
    }
    static function removeHost($userId = 0)
    {
        return self::updateOrCreate(['user_id' => $userId], ['user_id' => $userId, 'flag' => 0]);
    }
}
